package com.zzyl.serve.controller.member;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.serve.domain.AlertData;
import com.zzyl.serve.domain.CheckIn;
import com.zzyl.serve.dto.CheckInElderDto;
import com.zzyl.serve.dto.ElderDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.vo.DeviceDataGraphVo;
import com.zzyl.serve.service.FamilyMemberElderService;
import com.zzyl.serve.vo.CheckInElderVo;
import com.zzyl.serve.vo.FamilymemberVo;
import com.zzyl.serve.vo.LoginVo;
import com.zzyl.serve.vo.MemberVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.FamilyMember;
import com.zzyl.serve.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private FamilyMemberElderService familyMemberElderService;



    /**
     * 小程序端 用户登录
     */
	@PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);


        return R.ok(vo);
    }
    @PostMapping("/add")
    @ApiOperation("小程序端 绑定家人")
    public AjaxResult add(@RequestBody ElderDto dto) {

        familyMemberElderService.add(dto);


        return AjaxResult.success();
    }

    @GetMapping("/my")
    @ApiOperation("小程序端查询家人列表")
    public R<List<FamilymemberVo>> my() {

        List<FamilymemberVo> vo = familyMemberService.my();


        return R.ok(vo);
    }
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public R<List<MemberVo>> getByPage() {
        Long userId = UserThreadLocal.getUserId();
        List<MemberVo> vo = familyMemberService.selectPage(userId);
        return R.ok(vo) ;
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("小程序端查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {

        List<Map> deviceDetail = familyMemberService.queryServiceProperties(iotId);


        return success(deviceDetail);
    }

/**
 * 按天统计查询指标数据
 * 接地t址: /member/user/queryDeviceDataListByDay
 * 请求方式：GET
 */
@GetMapping("/queryDeviceDataListByDay")
@ApiOperation("按天统计查询指标数据")
public AjaxResult queryDeviceDataListByDay(String functionId , Long startTime , Long endTime ,String iotId) {

   List<DeviceDataGraphVo> list =  familyMemberService.queryDeviceDataListByDay(functionId,startTime,endTime,iotId);


    return AjaxResult.success(list);
}

/**
 * 按周统计查询指标数据
 * 接地址: /member/user/queryDeviceDataListByWeek
 * 请求方式：GET
 */

@GetMapping("/queryDeviceDataListByWeek")
@ApiOperation("按周统计查询指标数据")
public AjaxResult queryDeviceDataListByWeek(String functionId , Long startTime , Long endTime ,String iotId) {

    List<DeviceDataGraphVo> list =  familyMemberService.queryDeviceDataListByWeek(functionId,startTime,endTime,iotId);


    return AjaxResult.success(list);
}















}
